made name parameter of babl_format_new optional
authorØyvind Kolås <ok@src.gnome.org>
Mon, 29 Aug 2005 11:28:01 +0000 (11:28 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Mon, 29 Aug 2005 11:28:01 +0000 (11:28 +0000)
14 files changed:
ChangeLog
babl/babl-format.c
babl/base/model-rgb.c
babl/base/model-ycbcr.c
extensions/CIE-Lab.c
extensions/naive-CMYK.c
tests/Makefile.am
tests/float_to_u8.c
tests/grayscale_to_rgb.c
tests/rgb_to_bgr.c
tests/rgb_to_lab_to_rgb.c
tests/rgb_to_ycbcr.c
tests/rgb_to_ycbcr_to_rgb.c
tests/u8_to_float.c

index 8296a55fe084ac76c88db65e0011eb88ac647bf1..bc59154a9337d75ebc4b2e822ae30a3bcea9f8ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2005-08-29  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-format.c: (each_babl_format_destroy), (format_new),
+       (create_name), (babl_format_new): New API, name is now a key/value
+       pair, and if not set the name will be autogenerated.
+       * babl/base/model-rgb.c, 
+       * babl/base/model-ycbcr.c, 
+       * extensions/CIE-Lab.c, 
+       * extensions/naive-CMYK.c, 
+       * tests/Makefile.am,
+       * tests/float_to_u8.c,
+       * tests/grayscale_to_rgb.c, 
+       * tests/rgb_to_bgr.c, 
+       * tests/rgb_to_lab_to_rgb.c, 
+       * tests/rgb_to_ycbcr.c, 
+       * tests/rgb_to_ycbcr_to_rgb.c, 
+       * tests/u8_to_float.c: update to new API.
+
 2005-08-29  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-db.h: Do nor warn about collision during db_insert
index 1607a8cce07eb44a7884d00695b2614c7dcefff1..e63f78e86fba68c30eaab5cba20d5654aa2a4cd5 100644 (file)
@@ -28,7 +28,7 @@
 
 static int 
 each_babl_format_destroy (Babl *babl,
-                                void *data)
+                          void *data)
 {
   babl_free (babl->format.from);
   babl_free (babl->format.to);
@@ -39,13 +39,13 @@ each_babl_format_destroy (Babl *babl,
 
 static Babl *
 format_new (const char     *name,
-                  int             id,
-                  int             planar,
-                  int             components,
-                  BablModel      *model,
-                  BablComponent **component,
-                  BablSampling  **sampling,
-                  BablType      **type)
+            int             id,
+            int             planar,
+            int             components,
+            BablModel      *model,
+            BablComponent **component,
+            BablSampling  **sampling,
+            BablType      **type)
 {
   Babl *babl;
 
@@ -108,9 +108,36 @@ format_new (const char     *name,
   return babl;
 }
 
+
+static char buf[512]="";
+
+static const char *
+create_name (BablModel      *model,
+             int             components,
+             BablComponent **component,
+             BablType      **type)
+{
+  char *p = &buf[0];
+
+  sprintf (p, "%s ", model->instance.name);
+  p+=strlen (model->instance.name) + 1;
+
+  while (components--)
+    {
+      sprintf (p, "(%s as %s) ", 
+         (*component)->instance.name,
+         (*type)->instance.name);
+      p+=strlen ((*component)->instance.name) +
+         strlen ((*type)->instance.name     ) + strlen("( as ) ");
+      component++;
+      type++;
+    }
+  return buf;
+}
+
 Babl *
-babl_format_new (const char *name,
-                       ...)
+babl_format_new (void *first_arg,
+                 ...)
 {
   va_list varg;
   Babl            *babl;
@@ -124,18 +151,13 @@ babl_format_new (const char *name,
 
   BablSampling    *current_sampling = (BablSampling*) babl_sampling (1,1);
   BablType        *current_type     = (BablType*)     babl_type_id (BABL_U8);
-  const char      *arg              = name;
-
-  va_start (varg, name);
+  char            *name             = NULL;
+  void            *arg              = first_arg;
 
+  va_start (varg, first_arg);
   
   while (1)
     {
-      arg = va_arg (varg, char *);
-      if (!arg)
-        break;
-
-
       if (BABL_IS_BABL (arg))
         {
           Babl *babl = (Babl*)arg;
@@ -196,6 +218,11 @@ babl_format_new (const char *name,
         {
           id = va_arg (varg, int);
         }
+
+      else if (!strcmp (arg, "name"))
+        {
+          name = va_arg (varg, char *);
+        }
       
       else if (!strcmp (arg, "packed"))
         {
@@ -211,25 +238,34 @@ babl_format_new (const char *name,
         {
           babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
         }
+
+      arg = va_arg (varg, char *);
+      if (!arg)
+        break;
     }
     
   va_end   (varg);
 
+  babl = format_new (name?name:create_name (model, components, component, type),
+                     id,
+                     planar, components, model,
+                     component, sampling, type);
+  { 
+    Babl *ret;
+    ret = db_insert (babl);
 
-  babl = format_new (name, id,
-                           planar, components, model,
-                           component, sampling, type);
+    if (ret==babl)
+      {
+        return babl;
+      }
+    else
+      {
+        each_babl_format_destroy (babl, NULL);
+        return ret;
+      }
+  }
 
-  
-  if (db_insert (babl) == babl)
-    {
-      return babl;
-    }
-  else
-    {
-      each_babl_format_destroy (babl, NULL);
-      return NULL;
-    }
 }
 
 BABL_CLASS_TEMPLATE (babl_format)
index 73673f980697d35999d3828da60f4f8e6c3b3b73..aff0c28ea6a4855d0398c432f42731518c714ed2 100644 (file)
@@ -334,7 +334,7 @@ static void
 formats (void)
 {
     babl_format_new (
-    "srgb",
+    "name", "srgb",
     "id", BABL_SRGB,
     babl_model_id     (BABL_RGB_GAMMA_2_2),
     babl_type_id      (BABL_U8),
@@ -344,7 +344,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "srgba",
+    "name", "srgba",
     "id", BABL_SRGBA,
     babl_model_id     (BABL_RGBA_GAMMA_2_2),
     babl_type_id      (BABL_U8),
@@ -355,7 +355,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "rgba-float",
+    "name", "rgba-float",
     "id",              BABL_RGBA_FLOAT,
     babl_model_id     (BABL_RGBA),
     babl_type_id      (BABL_FLOAT),
@@ -366,7 +366,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "rgba-double",
+    "name", "rgba-double",
     "id",              BABL_RGBA_DOUBLE,
     babl_model_id     (BABL_RGBA),
     babl_type_id      (BABL_DOUBLE),
@@ -377,7 +377,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "rgb-float",
+    "name", "rgb-float",
     "id", BABL_RGB_FLOAT,
     babl_model_id     (BABL_RGB),
     babl_type_id      (BABL_FLOAT),
index 209b9de256270a9ee3871f57d1ce9683abe77030..2d810785fd8ba6f30887ff79895fa5844aca20df 100644 (file)
@@ -195,7 +195,7 @@ static void
 formats (void)
 {
   babl_format_new (
-    "y'cbcr420",
+    "name",        "y'cbcr420",
     "id",          BABL_YCBCR420,
     "planar",
     babl_model_id  (BABL_YCBCR),
@@ -211,7 +211,7 @@ formats (void)
   
 
   babl_format_new (
-    "y'cbcr422",
+    "name",        "y'cbcr422",
     "id",          BABL_YCBCR422,
     "planar",
     babl_model_id  (BABL_YCBCR),
@@ -226,7 +226,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "y'cbcr411",
+    "name",        "y'cbcr411",
     "id",          BABL_YCBCR411,
     "planar",
     babl_model_id  (BABL_YCBCR),
index ffa870840bb98899193467c397e1622bfa3ed6c3..0f321bd2fbc85102c04df37b5343a33044ea2fa6 100644 (file)
@@ -254,7 +254,7 @@ static void
 formats (void)
 {
   babl_format_new (
-    "CIE Lab float",
+    "name",        "CIE Lab float",
     babl_model     ("CIE Lab"),
 
     babl_type      ("float"),
@@ -264,7 +264,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "CIE Lab u8",
+    "name",        "CIE Lab u8",
     babl_model     ("CIE Lab"),
 
     babl_type      ("CIE u8 L"),
@@ -276,7 +276,7 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "cie-lab-u16",
+    "name",        "cie-lab-u16",
     babl_model     ("CIE Lab"),
 
     babl_type      ("CIE u16 L"),
index 90b6749b630bb6286b8e1703b959a65fdc4a08ed..b69ce385a997a861305738a5ad74ec7c1be45b16 100644 (file)
@@ -186,9 +186,10 @@ conversions (void)
 static void
 formats (void)
 {
-  babl_format_new ("CMYK float",
-      babl_model ("CMYK"),
-      babl_type ("float"),
+  babl_format_new (
+      "name",        "CMYK float",
+      babl_model     ("CMYK"),
+      babl_type      ("float"),
       babl_component ("cyan"),
       babl_component ("yellow"),
       babl_component ("magenta"),
index f801c0b30360c35a11d93126f92a9a4311c5a124..d9c82bbf84ba5105fa9f8331cd0ceef5fcb7ef44 100644 (file)
@@ -8,6 +8,7 @@ TESTS =                         \
        rgb_to_ycbcr_to_rgb     \
        srgb_to_lab_u8          \
        sanity                  \
+       types                   \
        babl_class_name
 
 float_to_u8_SOURCES         = float_to_u8.c
@@ -20,6 +21,7 @@ rgb_to_ycbcr_SOURCES        = rgb_to_ycbcr.c
 rgb_to_ycbcr_to_rgb_SOURCES = rgb_to_ycbcr_to_rgb.c
 babl_class_name_SOURCES     = babl_class_name.c
 sanity_SOURCES              = sanity.c
+types_SOURCES               = types.c
 
 
 AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
index 038bd67d21be4e6d2fb53efbbf8352e91daaca28..3d10222fc161880256eb4c7515b26e039a0a26a4 100644 (file)
@@ -53,14 +53,12 @@ test_float_to_rgb_u8 (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
       babl_model ("Y"),
       babl_type ("float"),
       babl_component ("Y"),
       NULL
     ),
     babl_format_new (
-      "bar",
       babl_model ("Y"),
       babl_type ("u8"),
       babl_component ("Y"),
index ad896da3074c94acaea8802a45cf47dc4c0c8be1..cc2c48ea517745f4a4ffae5637c8dd2512544a9a 100644 (file)
@@ -39,14 +39,12 @@ test (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
       babl_model ("Y"),
       babl_type ("float"),
       babl_component ("Y"),
       NULL
     ),
     babl_format_new (
-      "bar",
       babl_model ("RGB"),
       babl_type ("float"),
       babl_component ("R"),
index 1f47bf01282b4424e5f3ff1ff1cdb7b08c0dfabe..2f0d395cd9ce372622f5a7952d76b77c28624966 100644 (file)
@@ -46,7 +46,6 @@ test (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
       babl_model ("RGB"),
       babl_type ("u8"),
       babl_component ("R"),
@@ -55,7 +54,6 @@ test (void)
       NULL
     ),
     babl_format_new (
-      "bar",
       babl_model ("RGB"),
       babl_type ("u8"),
       babl_component ("B"),
index 6a1e6fe9d3575f9183a99db455ac0c6af7d39fc1..19a6ca66a64172ae10d958edcc7562dc2b696ba2 100644 (file)
@@ -76,7 +76,7 @@ test (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
+      "name", "foo",
       babl_model ("RGB"),
       babl_type ("float"),
       babl_component ("R"),
@@ -85,7 +85,7 @@ test (void)
       NULL
     ),
     babl_format_new (
-      "bar",
+      "name", "bar",
       babl_model ("CIE Lab"),
       babl_type ("float"), 
       babl_component ("CIE L"),
index d06b72fb50e6d2c889f9969ad4aceff0659be445..e07d1b0496a14ff58616d2cad5744247b48280f0 100644 (file)
@@ -53,7 +53,6 @@ test (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
       babl_model ("RGB"),
       babl_type ("float"),
       babl_component ("R"),
@@ -62,7 +61,6 @@ test (void)
       NULL
     ),
     babl_format_new (
-      "bar",
       babl_model ("Y'CbCr"),
       babl_type ("float"),
       babl_component ("Y'"),
index 0fbdf44d4259795d0276f7af8619d2e17ab7e2bb..117aba09f2f60941099d1c620595338b2c488239 100644 (file)
@@ -45,7 +45,7 @@ test (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
+      "name", "foo",
       babl_model ("RGB"),
       babl_type ("float"),
       babl_component ("R"),
@@ -54,7 +54,7 @@ test (void)
       NULL
     ),
     babl_format_new (
-      "bar",
+      "name", "bar",
       babl_model ("Y'CbCr"),
       babl_type ("float"), 
       babl_component ("Y'"),
index 6249609384debb61e41ecf629a9ae7afe3e413fe..d49c81267ca063d8c1e0868b1c4f85e0a45a6ad9 100644 (file)
@@ -38,14 +38,12 @@ test (void)
   
   fish = babl_fish (
     babl_format_new (
-      "foo",
       babl_model ("Y"),
       babl_type ("u8"),
       babl_component ("Y"),
       NULL
     ),
     babl_format_new (
-      "bar",
       babl_model ("Y"),
       babl_type ("float"),
       babl_component ("Y"),